<template>
  <el-card class="box-card el-card-flex">
    <div slot="header" class="clearfix">
      <span>
        用户映射
      </span>
    </div>
    <div class="text item">
      <el-form  @submit.native.prevent>
        <el-form-item>
          <el-input clearable v-model="searchContent" placeholder="请输入应用名" style="width:240px;" @keyup.enter.native='userMappingSearch'
            @clear='userMappingSearch'>
            <el-button slot="append" icon="el-icon-search" @click='userMappingSearch'></el-button>
          </el-input>
        </el-form-item>
      </el-form>
      <div class="el-flex el-box-column">
        <el-table :data="tableData" border stripe style="width: 100%" height="100%">
          <el-table-column min-width="100px" sortable :show-overflow-tooltip="true" type="index" label="序号"></el-table-column>
          <el-table-column min-width="100px" sortable :show-overflow-tooltip="true" prop="empName" label="集成平台用户名"></el-table-column>
          <el-table-column min-width="120px" sortable :show-overflow-tooltip="true" prop="empName" label="集成平台用户别名"></el-table-column>
          <el-table-column min-width="120px" sortable :show-overflow-tooltip="true" prop="empName" label="应用用户名"></el-table-column>
          <el-table-column min-width="120px" sortable :show-overflow-tooltip="true" prop="empName" label="应用用户别名"></el-table-column>
          <el-table-column min-width="100px" sortable prop="control" label="操作" align="center" fixed="right">
            <template slot-scope="scope">
              <el-button class="td-btn-icon" type="text" title="清空映射" @click="handleClear(scope.$index, scope.row)"><i
                  class="el-icon-remove-outline"></i></el-button>
              <el-button class="td-btn-icon" type="text" title="添加映射" @click="handleAdd(scope.$index, scope.row)"><i
                  class="el-icon-circle-plus-outline"></i></el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div></div>
      <el-pagination background @size-change="handleSizeChange" :current-page="currentPage" @current-change="handleCurrentChange"
        :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
      <div style="text-align: right;">
        <el-button type="primary">保存 <i class="el-icon-document-checked"></i>
        </el-button>
        <el-button type="danger" @click='subscriptionClose'>关闭 <i class="el-icon-close"></i>
        </el-button>
      </div>
    </div>
    <!-- 添加映射弹框 -->
    <el-dialog title="请选择用户" :visible.sync="dialogFormVisible" width='40%' :close-on-click-modal='false' :close-on-press-escape='false'>
      <el-form  @submit.native.prevent>
        <el-form-item>
          <el-input clearable v-model="searchContent" placeholder="请输入用户名/用户别名" style="width:240px;" @keyup.enter.native='userMappingSearch' @clear='userMappingSearch'>
            <el-button slot="append" icon="el-icon-search" @click='userMappingSearch'></el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-table :data="tableData" border stripe style="width: 100%" height="100%">
            <el-table-column min-width="100px" sortable :show-overflow-tooltip="true" prop="empName" label="用户名称"></el-table-column>
            <el-table-column min-width="100px" sortable :show-overflow-tooltip="true" prop="empName" label="集成平台用户名"></el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </el-card>
</template>

<script>
  import {
    Tree,
    Dialog,
    Table,
    TableColumn,
    Pagination,
    MessageBox,
    Message
  } from 'element-ui'
  import {
    subscriptiongManageData
  } from '@/api/applictionCenter/applicationCenter.js'
  export default {
    name: 'SubscriptionManage',
    components: {
      'el-tree': Tree, // 树形菜单
      'el-dialog': Dialog, // 对话框
      'el-table': Table, // 表格
      'el-table-column': TableColumn, // 表格列
      'el-pagination': Pagination, // 分页
    },
    created() {
      this.userMappingData(3, this.currentPage, this.pageSize)
    },
    data() {
      return {
        searchContent: '', //搜索值
        currentPage: 1,
        pageSize: 20,
        tableData: [], //表格数据
        dialogFormVisible: false,
        total: 0, //数据源总条数
      }
    },
    methods: {
      userMappingData(type, page, size, searchContent) {
        subscriptiongManageData(type, page, size, searchContent).then(res => {
          if (res.data.code == 10000) {
            this.total = res.data.data.total
            this.tableData = res.data.data.records
          }
        })
      },
      userMappingSearch() { //查询
        this.userMappingData(1, this.currentPage, this.pageSize, this.searchContent)
      },
      subscriptionClose() { //页面关闭
        this.$router.go(-1)
      },
      handleClear() { //清空映射

      },
      handleAdd() { //添加映射
        this.dialogFormVisible = true

      },
      handleSizeChange(val) { //条数
        this.pageSize = val
        this.userMappingData(3, this.currentPage, this.pageSize)
      },
      handleCurrentChange(val) { //页码
        this.currentPage = val
        this.userMappingData(3, this.currentPage, this.pageSize)
      }
    }
  }
</script>

<style>
</style>
